struct student { int rollno; char name[20]; char gender; }; main() { struct student a={4117,"Amit Jain",'m'}; printf("\n Rollno is %d",a.rollno); printf("\n Name is %s",a.name); printf("\n Gender is %c",a.gender); }
struct { int rollno; int age; char name[20]; }a; main() { printf("Enter the rollno,age,name\n"); scanf("%d %d %s",&a.rollno,&a.age,a.name); printf("Rollno = %d\nAge = %d\nName = %s",a.rollno,a.age,a.name); }
struct stud { int rollno; char name[20]; char gender; }; main() { struct stud a={4117,"Amit Jain",'m'}; struct stud *p; p=&a; printf("\n Rollno is %d",p->rollno); printf("\n Name is %s",p->name); printf("\n gender is %c",p->gender); printf("\n Rollno is %d",(*p).rollno); printf("\n Name is %s",(*p).name); printf("\n gender is %c",(*p).gender); }
Rollno is 4117 Name is Amit Jain gender is m Rollno is 4117 Name is Amit Jain gender is m
#include<stdio.h> struct stud { int rollno; char name[20]; char gender; }; void display(struct stud s) { printf("\n Rollno is %d",s.rollno); printf("\n Name is %s",s.name); printf("\n Gender is %c",s.gender); } main() { struct stud a = {4117,"Amit Jain" ,'m'}; struct stud b = {3012,"Raj Pande",'m'}; display(a); display(b); }
Rollno is 4117 Name is Amit Jain Gender is m Rollno is 3012 Name is Raj Pande Gender is m
#include<stdio.h> struct stud { int rollno; char name[20]; char gender ; }; void display(struct stud *p) { printf("\n Rollno is %d", p->rollno ); printf("\n Name is %s", p->name ); printf("\n Gender is %c",p->gender); } main() { struct stud a = {4117, "Amit Jain",'m'}; struct stud b = {3012, "Raj Pande",'m'}; display(&a); display(&b); }
Rollno is 4117 Name is Amit Jain Gender is m Rollno is 3012 Name is Raj Pande Gender is m
#include<stdio.h> struct date { unsigned int d; unsigned int m; unsigned int y; }; main() { struct date dt = {31, 12, 2014}; printf("Size of date is %d bytes\n", sizeof(dt)); printf("Date is %d/%d/%d", dt.d, dt.m, dt.y); }
Size of date is 12 bytes Date is 31/12/2014
#include<stdio.h> struct date { unsigned int d : 5 ; unsigned int m : 4 ; unsigned int y : 23 ; }; int main() { struct date dt = {31, 12, 2014}; printf("Size of date is %d bytes\n", sizeof(dt)); printf("Date is %d/%d/%d", dt.d, dt.m, dt.y); }
Size of date is 4 bytes Date is 31/12/2014
struct structure1 { int id1; int id2; char name; char c; float percentage; };
struct structure2 { int id1; char name; int id2; char c; float percentage; };